﻿using System;
using Dapper;
using MySql.Data.MySqlClient;

namespace BingoHallServerConsole.Helper.Account
{
	public class AccountHelper
	{

		/// <summary>
		/// 新增一个用户
		/// 添加成功，返回的int就是此用户的id；添加不成功，则返回0；
		/// </summary>
		/// <returns></returns>
		public static int AddOneAnonymousPlayer()
		{
			MySqlConnection conn = Program.ConnectionPool.getConnection(); //从连接池拿到一个连接
			var guid = Guid.NewGuid().ToString("N").ToLower();
			const string portrait = "https://www.baidu.com/img/baidu_jgylogo3.gif";
			var sql = $"INSERT INTO players(guid,portrait)VALUES('{guid}','{portrait}');";
			var count = conn.Execute(sql);
			if (count == 1)
			{
				var idSql = $"SELECT p.id from players p ORDER BY p.id desc limit 1;";
				var id = conn.QueryFirstOrDefault<int>(sql);
				return id;
			}
			return 0;
		}
	}
}
